<template>
  <div>
    <el-table :data="myWorkflows" style="width 100%" align="center">
      <el-table-column prop="item" label="申请标题" width="180"></el-table-column>
      <el-table-column prop="agree_user" label="处理人" width="180" :formatter="userFormatter"></el-table-column>
      <el-table-column prop="workflow_id" label="流程号" width="180"></el-table-column>
      <el-table-column prop="workflow_type" label="流程类型" width="180"></el-table-column>
      <el-table-column prop="number" label="申请单号" width="180"></el-table-column>
      <el-table-column label="操作" fixed="left" width="180">
        <template slot-scope="scope">
          <el-button type="primary" @click="checkInfo(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      myWorkflows: [],
      application: ""
    };
  },
  created() {
    this.fetchdata();
  },
  methods: {
    fetchdata() {
      this.axios
        .get("/get_my_last_finish_flow")
        .then(response => {
          if (response.data.value == 1) {
            this.myWorkflows = response.data.info;
          } else {
            this.$message("近两日内没有审批完成的流程");
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    checkInfo(row) {
      if (row.workflow_type == 1) {
        this.application = "companyapplication";
      }
      if (row.workflow_type == 2) {
        this.application = "accountapplication";
      }
      if (row.workflow_type == 3) {
        this.application = "macapplication";
      }
      this.$router.push({
        name: this.application,
        params: {
          number: row.number,
          workflowId: row.workflow_id,
          item: row.item,
          fromOther: 1,
          fromDaiban: 0
        }
      });
    },
    userFormatter(row) {
      return this.$store.getters.adminList.find(
        element => element.username == row.agree_user
      ).name;
    }
  }
};
</script>
